/**
 * iVprog, Alice:
 * @author LOB, RR; Ben Buchwald, Dennis Cosgrove
 */

package edu.cmu.cs.stage3.alice.core.question.ask;

import edu.cmu.cs.stage3.resourceBundle.I18n;

// String question = I18n.getString("msgSaveProgram");

import edu.cmu.cs.stage3.alice.core.property.StringProperty;
import edu.cmu.cs.stage3.swing.DialogManager;

public class AskUserForString extends edu.cmu.cs.stage3.alice.core.Question {

  private edu.cmu.cs.stage3.alice.core.Clock m_clock; // to lock (start/stop)

  private static final String str_title = I18n.getString("question"), str_question = I18n.getString("enterString");

  public final StringProperty 
     title = new StringProperty( this, "title", str_title ), // "Question"
     question = new StringProperty( this, "question", str_question ); 

  //Rem @Override
  public Class getValueClass () {
    return String.class;
    }

  //Rem @Override
  public Object getValue () {
    if ( m_clock != null) {
      m_clock.pause();
      }
    try {
      return DialogManager.showInputDialog( question.getStringValue(), title.getStringValue(), javax.swing.JOptionPane.QUESTION_MESSAGE );
    } finally {
      if (m_clock != null) {
        m_clock.resume();
        }
      }
    }

  //Rem @Override
  protected void started (edu.cmu.cs.stage3.alice.core.World world, double time) {
    super.started( world, time );
    if ( world != null ) {
      m_clock = world.getClock();
      }
    }

  //Rem @Override
  protected void stopped (edu.cmu.cs.stage3.alice.core.World world, double time) {
    m_clock = null;
    super.stopped( world, time );
    }

  }
